package com.wentao.mall.api

import com.wentao.mall.dao.MerchantDao
import com.wentao.mall.dao.UserDao
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/admin")
class AdminController(
    val merchantDao: MerchantDao,
    val userDao: UserDao
) {
    @PostMapping("/merchant/add")
    fun merchantAdd(@RequestBody merchant: Merchant): Result {
        merchantDao.save(merchant)
        return Result.success()
    }

    @GetMapping("/user/list")
    fun userList(): Result {
        val list = userDao.findAll()
        return Result.success(list)
    }

    @PostMapping("/user/add")
    fun init(user: User): Result {
        userDao.save(user)
        return Result.success()
    }

    @PostMapping("/user/delete")
    fun userDelete(id: Int): Result {
        userDao.deleteById(id)
        return Result.success()
    }

//    @GetMapping("/loginSuccess", "/logoutSuccess")
//    fun loginSuccess(): Result {
//        return Result.success()
//    }
//
//    @GetMapping("/loginFail")
//    fun loginFail(): Result {
//        return Result.error("login fail")
//    }


}
